import java.io.File;

public class VM_Client_Delete implements Runnable
{

  static private final String BDuser = "FIB";
  static private final String BDpassword = "pxCloud2011";
  
  private String idExperiment;
  
  /**
  * Deletes experiment with idExperiment=idExperiment, both DB entry and results folder
  */

  public VM_Client_Delete ( String idExperiment ) {
    this.idExperiment = idExperiment;
    new Thread( this ).start();
  }
  
  public void run() {
    GestorBD gestorbd = new GestorBD();
      
    try{
      //Borramos la entrada de la base de datos.
      gestorbd.modificar("vm", BDuser, BDpassword,
      "DELETE FROM vm.EXPERIMENTS WHERE IDEXPERIMENT='"+this.idExperiment+"';");
      
      //Si existe un directorio con resultados también lo borramos.
      File dir = new File(idExperiment+"Res");
      if (dir.isDirectory()){
	String files[] = dir.list();
	for (int i=0;i<files.length;i++){
	  File file = new File(idExperiment+"Res/"+files[i]);
	  file.delete();
	}
      dir.delete();
      }
	
    }
    catch (Exception e){
      e.printStackTrace();
    }
  }
  
}
